package com.jumi.microservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jumi.microservice.entity.CpsUserCash;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author scw
 * @date 2021/1/8
 */
@Mapper
public interface CpsUserCashMapper extends BaseMapper<CpsUserCash> {
    /**
     * 所有提现审核中总额
     *
     * @param
     * @return
     */
    @Select("select ifnull(sum(amount),0) from cps_user_cash where del_flag = 0 and status = 0  and DATE_FORMAT(create_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')")
    BigDecimal totalCheckMoney();

    /**
     * 所有提现审核中总额 根据用户查询
     *
     * @param userIdList
     * @return
     */
    @Select("<script>select ifnull(sum(amount),0) from cps_user_cash where del_flag = 0 and status = 0  and DATE_FORMAT(create_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')  <if test='userIdList !=null and userIdList.trim()!=&quot;&quot;'>and uid in ( ${userIdList} )</if></script>")
    BigDecimal totalCheckMoney(@Param("userIdList") String userIdList);

    /**
     * 根据用户ID列表获取审核中金额
     *
     * @param userIdList
     * @return
     */
    @Select("<script>" +
            "select \n" +
            "uid as userId,IFNULL(sum(amount),0) as amount \n" +
            "from cps_user_cash \n" +
            "where del_flag = 0 and status = 0  and DATE_FORMAT(create_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m') \n" +
            "and uid in  ( ${userIdList} ) " +
//            "   <foreach item='item' index='index' collection='userIdList' open='(' separator=',' close=')'>" +
//            "       #{item}" +
//            "   </foreach>" +
            "group by uid " +
            "</script>"
    )
    List<Map<String, Object>> checkingCashByUserIdList(@Param("userIdList") String userIdList);


    /**
     * 本月提现金额总额
     *
     * @param uid
     * @return
     */
    @Select("SELECT ifnull(sum(amount),0) FROM cps_user_cash WHERE del_flag = 0 AND status IN (0,1,3) AND uid = #{uid} AND DATE_FORMAT(create_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')")
    BigDecimal getTotalAmountByMonth(Long uid);
}
